<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>顶点、几何结构</title>
  <style>
    .box {
      width: 800px;
      height: 800px;
      border: 1px solid red;
    }
  </style>
</head>
<body>
  <div class="box"></div>

  <script src="../js/three.js"></script>
  <script type="module">
    import { createBaseObj, testAnimation, createViewController, addHelpLine } from '../js/myThree.js'

    const oBox = document.getElementsByClassName('box')[0]

    const { scene, camera, renderer } = createBaseObj(oBox)
    addHelpLine(scene)


    /** 初始 */
    const init = () => {
      const geometry = new THREE.BufferGeometry()

      /** 类型数组创建顶点数据 */
      const vertices = new Float32Array([
        0, 0, 0,
        50, 0, 0,
        0, 100, 0,
        0, 0, 10,
        0, 0, 100,
        50, 0, 10
      ])

      /** 创建属性缓存对象 */
      geometry.setAttribute('position', new THREE.BufferAttribute(vertices, 3))
      const colors = new Float32Array([
        1, 0, 0,
        0, 1, 0,
        0, 0, 1,

        1, 1, 0,
        0, 1, 1,
        1, 0, 1
      ])
      geometry.setAttribute('color', new THREE.BufferAttribute(colors, 3))

      // const material = new THREE.LineBasicMaterial({
      //   color: 0xfa60ff,
      //   side: THREE.DoubleSide
      // })
      // const material = new THREE.PointsMaterial({
      //   // 使用顶点颜色数据渲染模型，不需要再定义color属性
      //   // color: 0xfa60ff,
      //   vertexColors: true, //Boolean 是否使用顶点颜色
      //   size: 10.0 //点对象像素尺寸
      // })
      const material = new THREE.MeshBasicMaterial({
        // 使用顶点颜色数据渲染模型，不需要再定义color属性
        // color: 0xfa60ff,
        vertexColors: true, //Boolean 是否使用顶点颜色
        size: 10.0 //点对象像素尺寸
      })

      // const mesh = new THREE.Line(geometry, material)
      // const points = new THREE.Points(geometry, material)
      const mesh = new THREE.Mesh(geometry, material)
      scene.add(mesh)

      animation()
    }

    /** 渲染中 */
    const doSth = () => {

    }

    const control = createViewController(renderer.domElement, camera)
    const animation = testAnimation({ scene, camera, renderer }, doSth)

    init()
  </script>
</body>
</html>